MAX_SIZE = 10000001
isprime = Array.from({ length: MAX_SIZE }, (_, i) => true);
prime = []
SPF = Array.from({ length: MAX_SIZE }, (_, i) => null);

function manipulated_seive(N) {
    isprime[0] = isprime[1] = false;
    for (var i = 2; i < N; i++) {
        if (isprime[i]) {
            prime.push(i);
            SPF[i] = i
        }
        j = 0
        while (j < prime.length && i * prime[j] < N && prime[j] <= SPF[i]) {
            isprime[i * prime[j]] = false;
            SPF[i * prime[j]] = prime[j];
            j++;
        }
    }
}



manipulated_seive(MAX_SIZE);
class Primes {
    static * stream() {
        var p = 0;
        while (true) {
            yield prime[p++];
        }
    }
}
console.log(prime.slice(-1))